import { BasicTitle } from "@/components/Basic";
import { isFunction } from "@/utils/is";
import { useMemo } from "react";
import "../style/TableTitle.less";

interface TableTitlePropsType {
	title?: string | ((data: Recordable) => string);
	getSelectRows?: () => any[];
	helpMessage?: string | string[];
}

export default function BasicTableTitle(props: TableTitlePropsType) {
	const prefixCls = "basic-table-title";

	const getTitle = useMemo(() => {
		const { title, getSelectRows = () => {} } = props;
		let tit = title;
		if (isFunction(title)) {
			tit = title({
				selectRows: getSelectRows()
			});
		}
		return tit;
	}, [props.title]);

	return getTitle ? (
		<BasicTitle className={prefixCls} helpMessage={props.helpMessage}>
			{getTitle}
		</BasicTitle>
	) : null;
}
